import { _decorator, Component, Node, Label, AudioClip } from 'cc';
const { ccclass, property } = _decorator;

import { SSS_Consts } from "../../../../Script/Data/SSS_Consts";
import { bdlMgr } from "../../../../Script/Manager/BundleManager_S";
import SSS_GameEventManager, { SS_GameEventData } from "../../../../Script/Manager/SSS_GameEventManager";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';

@ccclass('LianLianKan_LosePanel')
export default class LianLianKan_LosePanel extends Component {
    public static Instance: LianLianKan_LosePanel;
    @property(Node)
    public Button_menu: Node | null = null;
    @property(Node)
    public Button_replay: Node | null = null;
    @property(Node)
    public Button_revive: Node | null = null;
    @property(Label)
    Label_score: Label | null = null;
    @property(Label)
    Label_high_score: Label | null = null;
    index: number;
    onLoad() {
        LianLianKan_LosePanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        let audio_root = `audio/fail`;
        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });
    }
    ShowOff() {
        this.node.destroy();
        this.RemoveListener();
    }
    Refresh() {
        // this.Label_score.string = `本局得分：${DragTetris_GameData.GetScore()}`;
        // this.Label_high_score.string = `最高纪录：${DragTetris_GameStorage.data.high_score}`;

        // this.Label_score.string = `${Minesweeper_GameData.GetScore()}`;
        // this.Label_high_score.string = `${S2048_GameStorage.data.high_score}`;
    }
    AddListener() {
        this.Button_menu.on(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_replay.on(Node.EventType.TOUCH_END, this.On_Button_replay, this);
        this.Button_revive.on(Node.EventType.TOUCH_END, this.On_Button_revive, this);
    }
    RemoveListener() {
        this.Button_menu.off(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_replay.off(Node.EventType.TOUCH_END, this.On_Button_replay, this);
        this.Button_revive.off(Node.EventType.TOUCH_END, this.On_Button_revive, this);
    }
    On_Button_menu() {
        // console.log(`On_Button_menu`);

        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Menu);
        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_replay() {
        // console.log(`On_Button_replay`);

        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Replay);
        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_revive() {
        // console.log(`On_Button_revive`);

        let audio_root = `audio/life received`;
        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });

        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Revive);
        SSS_AudioManager.PlayButtonAudio();
    }
}